home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#49 (Oct 89)
/
SC #49.sit
/
Driver Code
/
GNEFilter.a
< prev
next >
Wrap
Text File
|
1988-01-12
|
4KB
|
117 lines
TITLE 'GNE filter'
BLANKS ON
CASE ON
String Pascal
* The GNE Filter permits the pump driver to function asynchronously, but
* at non-interrupt level. Whenever a serial IO call completes, the serial
* completion routine posts an app1Evt with the parameter block pointer as
* the message. The GNE filter is called at the end of the _GetNextEvent trap,
* and thus receives all events. The filter first excludes all events other
* than app1Evts (passing then to the application for handling), then checks
* the ioRefnum field of the parameter block. If it is negative, the event
* belongs to a driver, and thus it is handled by the filter. The
* _GetNextEvent function code is returned as false, so that the application
* does not handle the event. If the ioRefnum is positive, the event is passed
* to the application.
* When the filter has found a driver app1Evt, the message will contain a
* pointer to a parameter block used for a serial IO driver. This parameter
* block contains a pointer to the currently executing pump driver parameter
* block in its ioMisc field, and this parameter block contains the pump
* driver reference number in its ioRefnum. We check this against a list of
* up to eight (arbitrary limit) reference numbers of cooperating drivers. If
* the driver is in the list, we pass it the event via an immediate control
* call. The routine does not check to see if the driver can handle app1Evts,
* simply because any driver which is not written to cooperate with this
* routine would be excluded by the check for membership in the cooperating
* driver list.
* The routine is structured much like a driver, in that the first word is
* an offset to the routine, and local storage for data is incorporated into
* the routine. This is because the routine is installed by a driver, and thus
* cannot utilize application globals. Also, the rotuine is written so that it
* can be shared by several drivers to service their app1Evts. The routine
* is linked as a resource of type 'GNEF', and named 'GNEFilter',
* so that it can be loaded into the heap by the resource manager.
PRINT OFF
INCLUDE 'Traps.a'
INCLUDE 'ToolEqu.a'
INCLUDE 'QuickEqu.a'
INCLUDE 'SysEqu.a'
INCLUDE 'SysErr.a'
INCLUDE 'GNEglobals.inc'
INCLUDE 'Quickdraw.inc'
LOAD 'FlowCtlMacs.d'
PRINT ON
* The stackframe for the routine.
StackFrame RECORD {A6Link},DECR
Result DS.W 1
RetAddr DS.L 1
A6Link DS.L 1
LocalSize equ *
ENDR
MAIN
WITH EventRecord,StackFrame,GNEGlobals
Entry DC.W GNEFilter ;Offset to GNE filter
DCB.B GNEGlobalSize,0
GNEFilter:
* If the event is not an app1Evt, go to the next event in the GNE filter
* chain, which we previously stored in GNE_Next
LEA Entry,A0
CMP.W #app1Evt,what(A1)
BNE.S Out
* We have an app1Evt. Check to see if the ioRefnum is negative.
LINK A6,#LocalSize
MOVEM.L A2/D1-D2,-(SP)
MOVE.L message(A1),A2
MOVE.L ioMisc(A2),A2
MOVE.W ioRefNum(A2),D1
If# GE Then.S
GoTo#.S PreOut
EndIf#
* We have a negative ioRefnum. Check to see if it is in the list of ioRefnums
* we are cooperating with. If it is, pass the event to the driver by setting
* up a parameter block for an immediate call to the control routine.
MOVE.L Control_Ptr(A0),A2
LEA Drvr_num(A0),A0
MOVE.W (A0)+,D2
Loop For# D2 DownTo #1 Do.S
MOVE.W (A0)+,D0
If# D0 EQ.W D1 Then.S
MOVE.W D1,ioRefNum(A2)
MOVE.W #accEvent,csCode(A2)
MOVE.L A1,csParam(A2)
MOVE.L A2,A0
_Control ,immed
CLR.W D0
MOVE.W D0,Result(A6)
Leave#.S Loop
EndIf#
EndF#
PreOut:
MOVEM.L (SP)+,A2/D1-D2
UNLK A6
LEA Entry,A0
Out:
MOVE.L GNE_Next(A0),A0
JMP (A0)
ENDP
END